//
//  TFStatusToolBar.swift
//  weiboSina
//
//  Created by admin on 16/1/3.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class TFStatusToolBar: UIView {

    
    private var retweetBtn: UIButton!
    private var commentBtn: UIButton!
    private var attitudeBtn: UIButton!
    /**
     设置数据
     */
    var statusViewModel: TFStatusViewModel?{
        didSet{
        
            /**
            设置三个按钮的数据
            */
            retweetBtn.setTitle(statusViewModel?.repostsCount, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsCount, forState: .Normal)
            attitudeBtn.setTitle(statusViewModel?.attitudesCount, forState: .Normal)
        
        
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
    
        /**
        添加三个按钮
        */
                
       retweetBtn = addChildButton("转发", imgNamed: "timeline_icon_retweet")
      commentBtn = addChildButton("评论", imgNamed: "timeline_icon_comment")
       attitudeBtn = addChildButton("赞", imgNamed: "timeline_icon_unlike")
        
        let sp1 = addSpliteView()
        let sp2 = addSpliteView()
        
        // 转发按钮
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        // 评论按钮
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.top.equalTo(retweetBtn)
            make.bottom.equalTo(retweetBtn)
            make.width.equalTo(attitudeBtn.snp_width)
        }
        // 评论
        attitudeBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.trailing.equalTo(self)
            make.top.equalTo(commentBtn)
            make.bottom.equalTo(commentBtn)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
 
        
    
    }
    
    private func addChildButton(title: String,imgNamed: String) -> UIButton{
    
        let button = UIButton(textColor: UIColor.darkGrayColor(), textSize: 14)
        // 设置不同状态的背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imgNamed), forState: UIControlState.Normal)
        // 设置标题
        button.setTitle(title, forState: UIControlState.Normal)
        addSubview(button)
        return button
    }
    
    /**
    添加分割线
    */
    private func addSpliteView() -> UIView{
    
    let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(imageView)
        return imageView
    }
}
